import { defineConfig } from 'vite';
import { resolve } from 'path';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { visualizer } from 'rollup-plugin-visualizer';

// https://vitejs.dev/config/
export default defineConfig({
  base: '/',
  plugins: [vue(), vueJsx(), visualizer()],
  resolve: {
    alias: {
      '~': resolve(__dirname, './'),
      '@': resolve(__dirname, 'src'),
    },
    extensions: ['.js', '.ts', '.jsx', '.tsx', '.json', '.vue', '.mjs'],
  },
  server: {
    hmr: { overlay: false },
    port: 9000,
    open: true,
    cors: true,
    proxy: {
      '/api': {
        target: 'http://122.51.52.168:9000/',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path.replace('/api', ''),
      },
    },
  },
  // https://www.vitejs.net/config/#build-commonjsoptions
  build: {
    commonjsOptions: {
      ignoreDynamicRequires: false,
      transformMixedEsModules: true,
      brotliSize: false,
      sourceMap: false,
    },
  },
});
